/*
 * tcpclient.h
 *
 *  Created on: 2011-8-19
 *      Author: chenl
 *     Purpose:
 *        Note:
 */

#include "common_connect.h"
#ifndef WIN32
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#endif

class CTcpClient : public CConnect
{
public:
	CTcpClient() : m_fd(enmInvalidFD) {}
	CTcpClient(int fd) : m_fd(fd) {}
	virtual ~CTcpClient(){}
public:
	virtual int32_t Connect(int fd)
	{
		int32_t ret = S_OK;
		CConnect::Connect();
		switch(GetConnectonStatus())
		{
		case CConnect::enmConnStatus_Closed:
		case CConnect::enmConnStatus_Connecting:
			m_fd = fd;
			break;
		case CConnect::enmConnStatus_Connected:
		}

		SetConnectonStatus(CConnect::enmConnStatus_Connected);

		return ret;
	}
	virtual int32_t Disconnect()
	{
		close(m_fd);
		m_fd = enmInvalidFD;
		SetConnectonStatus(CConnect::enmConnStatus_Closed);
		return S_OK;
	}

	virtual uint32_t Recv(char *pszBuf, uint32_t uLen);
	virtual uint32_t Send(const char *pszBuf, uint32_t uLen);

private:
	int m_fd;
};
